//
//  PersonNetWork.m
//  Shengzhuli
//
//  Created by 卡忙科技 on 16/8/18.
//  Copyright © 2016年 kamangkeji. All rights reserved.
//

#import "PersonNetWork.h"
#import "GFXNetworkHandle.h"
#import "NormalShopGoodsModel.h"
#import "SourceModel.h"
#import "ChargeListModel.h"
#import "TeamModel.h"
#import "AdderModel.h"
#import "HomeYueModel.h"

NSString * const GetPersonInfo = @"auth/user/info";//用户信息
NSString * const ModifyPersonInfo = @"auth/user/update/info";//修改用户信息
NSString * const FileUp = @"file/up";//上传图片

NSString * const EditcardInfo = @"auth/userCard/update/info";//编辑名片
NSString * const cardInfo = @"auth/userCard/info/send";//获取名片
NSString * const SaoCardInfo = @"user/saoUserCard/info/send";//扫描获取别人名片
NSString * const GetOtherCardInfo = @"auth/user/userCard/info/send";//获取别人名片
NSString * const Sources = @"auth/list/industry";//获取资源
NSString * const AddCardFriends = @"auth/user/add/friend";//添加人脉

NSString * const TeamLists = @"auth/list/getMyTeams";//我的团队

NSString * const Integral = @"auth/user/integral";//获取积分
NSString * const IntegralDetail = @"auth/user/integralDetail";//获取积分

NSString * const MykeepList = @"auth/keep/product/list";//我的关注
NSString * const MybrowseList = @"auth/browse/product/list";//我的浏览
NSString * const OptionUrl = @"auth/user/suggestion";//意见反馈
NSString * const ShareContent = @"auth/member/share";//分享内容
NSString * const IsAddInfo = @"auth/shop/go/to/create";//是否加盟过
NSString * const NearAdder = @"auth/user/list/near/partner";//附近合作人
NSString * const AllowLook = @"auth/user/update/allowStutas";//允许查看名片


NSString * const GetService = @"auth/user/admin/service";//获取客服
NSString * const GetReportList = @"auth/apply/activity/list";//获取已报名列表


@implementation PersonNetWork

+ (void)getPersonInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSString *errorCode,PersonInfo *info))response
{
    [[GFXNetworkHandle shareHandle]post:GetPersonInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            PersonInfo *info = [PersonInfo objectWithDict:json[@"result"]];
            response(YES,json[@"message"],json[@"status"],info);
        }else{
            response(NO,json[@"message"],json[@"status"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil,nil);
    }];
}

+ (void)modifyPersonInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:ModifyPersonInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)upLoadImageWithParame:(NSDictionary *)parames image:(UIImage *)image response:(void (^)(BOOL success,NSString *msg,NSString *path))response
{
    [[GFXNetworkHandle shareHandle]post:FileUp params:parames constructingBodyWithBlock:^(id formData) {
        NSData *data = UIImageJPEGRepresentation(image, 0.5);
        NSDateFormatter * formatter = [[NSDateFormatter alloc] init];
        [formatter setDateFormat:@"yyyy-MM-dd HH:mm:ss"];
        NSString * nowtimeStr = [NSString stringWithFormat:@"%ld", (long)[[NSDate date] timeIntervalSince1970]];
        NSString *fileName = [NSString stringWithFormat:@"%@.png",nowtimeStr];
        [formData appendPartWithFileData:data name:@"pictureFile" fileName:fileName mimeType:@"image/png"];
    } progress:nil success:^(id json) {
        response(YES,json[@"message"],json[@"result"]);
    } failure:^(id json) {
        response(NO,json[@"message"],nil);
    }];
}


+ (void)getMyListWithParame:(NSDictionary *)parames type:(MyList)type response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    NSString *url = (type == MyListKeep)?MykeepList:MybrowseList;
    [[GFXNetworkHandle shareHandle]post:url params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                NormalShopGoodsModel *model = [NormalShopGoodsModel objectWithDict:dict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getShareContentWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,ShareContentModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:ShareContent params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            ShareContentModel *model = [ShareContentModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getAddInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,SellerInfoModel *model))response
{
    [[GFXNetworkHandle shareHandle]post:IsAddInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            SellerInfoModel *model = [SellerInfoModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],model);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)optionWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:OptionUrl params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)editCardInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:EditcardInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)cardInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,CardInfoModel *info))response
{
    [[GFXNetworkHandle shareHandle]post:cardInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSLog(@"json = %@",json);
            CardInfoModel *infoModel = [CardInfoModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],infoModel);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getOtherCardInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,CardInfoModel *info))response
{
    [[GFXNetworkHandle shareHandle]post:GetOtherCardInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            CardInfoModel *infoModel = [CardInfoModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],infoModel);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getSourcesWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *sources))response
{
    [[GFXNetworkHandle shareHandle]post:Sources params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *list = [NSMutableArray array];
            NSArray *jsonArr = json[@"result"];
            if (jsonArr.count>0) {
                for (NSDictionary *dict in jsonArr) {
                    SourceModel *model = [SourceModel objectWithDict:dict];
                    [list addObject:model];
                }
            }
            response(YES,json[@"message"],list);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        NSLog(@"%@",error);
        response(NO,NetworkError,nil);
    }];
}

+ (void)getIntegralWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSInteger integral))response
{
    [[GFXNetworkHandle shareHandle]post:Integral params:parames success:^(id json) {
        NSLog(@"%@",json);
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"],[json[@"result"][@"total"] integerValue]);
        }else{
            response(NO,json[@"message"],0);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,0);
    }];
}

+ (void)getIntegralDetailWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *integrals))response
{
    [[GFXNetworkHandle shareHandle]post:IntegralDetail params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *arr = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                ChargeListModel *model = [ChargeListModel objectWithDict:dict];
                [arr addObject:model];
            }
            response(YES,json[@"message"],arr);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}


+ (void)getSaoCardInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,CardInfoModel *info))response
{
    [[GFXNetworkHandle shareHandle]post:SaoCardInfo params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            CardInfoModel *infoModel = [CardInfoModel objectWithDict:json[@"result"]];
            response(YES,json[@"message"],infoModel);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)addCardFriendsInfoWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:AddCardFriends params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}


+ (void)getMyTeamListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:TeamLists params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                TeamModel *model = [TeamModel objectWithDict:dict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getNearAdderWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:NearAdder params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                AdderModel *model = [AdderModel objectWithDict:dict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)allowLookCardWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg))response
{
    [[GFXNetworkHandle shareHandle]post:AllowLook params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"]);
        }else{
            response(NO,json[@"message"]);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError);
    }];
}

+ (void)getServiceWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSString *service))response
{
    [[GFXNetworkHandle shareHandle]post:GetService params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            response(YES,json[@"message"],json[@"result"][@"service"]);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}

+ (void)getMyReportListWithParame:(NSDictionary *)parames response:(void (^)(BOOL success,NSString *msg,NSArray *lists))response
{
    [[GFXNetworkHandle shareHandle]post:GetReportList params:parames success:^(id json) {
        if ([json[@"status"] isEqualToString:SuccessStatus]) {
            NSMutableArray *lists = [NSMutableArray array];
            for (NSDictionary *dict in json[@"result"]) {
                HomeYueModel *model = [HomeYueModel objectWithDict:dict];
                [lists addObject:model];
            }
            response(YES,json[@"message"],lists);
        }else{
            response(NO,json[@"message"],nil);
        }
    } failure:^(NSError *error) {
        response(NO,NetworkError,nil);
    }];
}


@end
